<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:form prependId="false" id="uplaodFileForm">
                <p:panel header="Invoices to be posted" id="allinvoicespanel">
                    <p:messages />
                    <p:dataTable value="#{customerInvoiceEntityController.unpostedInvoices}" var="item">
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_id}"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_type}"/>
                            </f:facet>
                            <h:outputText value="#{item.type}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_status}"/>
                            </f:facet>
                            <h:outputText value="#{item.status}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_customerAccount}"/>
                            </f:facet>
                            <h:outputText value="#{item.customerAccount}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_amount}"/>
                            </f:facet>
                            <h:outputText value="#{item.amount}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_dueDate}"/>
                            </f:facet>
                            <h:outputText value="#{item.dueDate}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_createdAt}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdAt}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListCustomerInvoiceEntityTitle_createdBy}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdBy.fullname}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton image="ui-icon ui-icon-search" action="#{customerInvoiceEntityController.prepareView}" ajax="false">
                                <f:setPropertyActionListener target="#{customerInvoiceEntityController.current}" value="#{item}" />
                            </p:commandButton>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:menuButton value="Post" >
                                <p:menuitem ajax="false" value="email" 
                                            action="#{customerInvoiceEntityController.postInvoiceViaEmailAndRedirectToView}" rendered="#{item.toBePosted}">
                                    <f:setPropertyActionListener target="#{customerInvoiceEntityController.current}" value="#{item}" />
                                </p:menuitem>
                                <p:menuitem value="mark posted" rendered="#{item.toBePosted}" action="#{customerInvoiceEntityController.postInvoice}" update="@form">
                                    <f:setPropertyActionListener target="#{customerInvoiceEntityController.current}" value="#{item}" />
                                </p:menuitem>
                            </p:menuButton>
                        </p:column>
                    </p:dataTable>
                </p:panel>

            </h:form>
        </ui:define>
    </ui:composition>

</html>
